<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>Spirng事务失效的场景 | buqiugouda的博客主页</title><meta name="author" content="不求勾搭"><meta name="copyright" content="不求勾搭"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="1. Spring 事务的实现方式在总结Spring事务失效场景前先明确下Spring提供的两种事务实现方式  声明式事务：主要利用@Transactional注解或者xml配置，使用这种方式可以将事务管理和业务代码分离。  编程式事务：带来了很大的灵活性，但很难维护。在spring中提供了专门的类TransactionTemplate，它的excute是一个函数式接口，实现了事务的功能，用法如下">
<meta property="og:type" content="article">
<meta property="og:title" content="Spirng事务失效的场景">
<meta property="og:url" content="http://buqiugouda.gitee.io/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/Spring/Spring%E4%BA%8B%E5%8A%A1%E5%A4%B1%E6%95%88%E7%9A%84%E5%9C%BA%E6%99%AF/index.html">
<meta property="og:site_name" content="buqiugouda的博客主页">
<meta property="og:description" content="1. Spring 事务的实现方式在总结Spring事务失效场景前先明确下Spring提供的两种事务实现方式  声明式事务：主要利用@Transactional注解或者xml配置，使用这种方式可以将事务管理和业务代码分离。  编程式事务：带来了很大的灵活性，但很难维护。在spring中提供了专门的类TransactionTemplate，它的excute是一个函数式接口，实现了事务的功能，用法如下">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://buqiugouda.gitee.io/img/covers/cover2.png">
<meta property="article:published_time" content="2020-05-14T16:00:00.000Z">
<meta property="article:modified_time" content="2023-08-21T08:08:30.960Z">
<meta property="article:author" content="不求勾搭">
<meta property="article:tag" content="Spring">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://buqiugouda.gitee.io/img/covers/cover2.png"><link rel="shortcut icon" href="/myblog/img/favicon.ico"><link rel="canonical" href="http://buqiugouda.gitee.io/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/Spring/Spring%E4%BA%8B%E5%8A%A1%E5%A4%B1%E6%95%88%E7%9A%84%E5%9C%BA%E6%99%AF/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="stylesheet" href="/myblog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/myblog/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Spirng事务失效的场景',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-08-21 16:08:30'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = url => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      link.onload = () => resolve()
      link.onerror = () => reject()
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 5.4.2"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://foruda.gitee.com/avatar/1676921533047997408/590832_buqiugouda_1620800091.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/myblog/archives/"><div class="headline">文章</div><div class="length-num">11</div></a><a href="/myblog/tags/"><div class="headline">标签</div><div class="length-num">9</div></a><a href="/myblog/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/myblog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/myblog/img/covers/cover2.png')"><nav id="nav"><span id="blog-info"><a href="/myblog/" title="buqiugouda的博客主页"><span class="site-name">buqiugouda的博客主页</span></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/myblog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Spirng事务失效的场景</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="fa-fw post-meta-icon far fa-calendar-alt"></i><span class="post-meta-label">发表于</span><time datetime="2020-05-14T16:00:00.000Z" title="发表于 2020-05-15 00:00:00">2020-05-15</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/myblog/categories/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/">读书笔记</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/myblog/categories/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/Spring/">Spring</a></span></div><div class="meta-secondline"></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="1-Spring-事务的实现方式"><a href="#1-Spring-事务的实现方式" class="headerlink" title="1. Spring 事务的实现方式"></a>1. Spring 事务的实现方式</h2><p>在总结Spring事务失效场景前先明确下Spring提供的两种事务实现方式</p>
<ul>
<li><p>声明式事务：主要利用<code>@Transactional</code>注解或者xml配置，使用这种方式可以将事务管理和业务代码分离。</p>
</li>
<li><p>编程式事务：带来了很大的灵活性，但很难维护。<br>在spring中提供了专门的类TransactionTemplate，它的excute是一个函数式接口，实现了事务的功能，用法如下</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="meta">@Autowired</span></span><br><span class="line"><span class="keyword">private</span> TransactionTemplate transactionTemplate;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">saveOrUpdateModel</span><span class="params">(ModelInfoEntity modelInfo)</span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="type">SubdistSapDistServeEntity</span> <span class="variable">serve</span> <span class="operator">=</span> subdistSapDistServeService.getById(modelInfo.getThemeId());</span><br><span class="line"></span><br><span class="line">    <span class="type">FieldComponentEntity</span> <span class="variable">component</span> <span class="operator">=</span> fieldComponentService.getById(modelInfo.getModelId());</span><br><span class="line"></span><br><span class="line">    <span class="comment">/*省略对象属性更改*/</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">//使用lamda函数式组装需要操作数据的方法</span></span><br><span class="line">    <span class="type">Boolean</span> <span class="variable">execute</span> <span class="operator">=</span> template.execute((status) -&gt; &#123;</span><br><span class="line"></span><br><span class="line">        subdistSapDistServeService.save(serve);</span><br><span class="line"></span><br><span class="line">        fieldComponentService.updateById(component);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> Boolean.TRUE;</span><br><span class="line">    &#125;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="2-Spring事务失效的场景"><a href="#2-Spring事务失效的场景" class="headerlink" title="2. Spring事务失效的场景"></a>2. Spring事务失效的场景</h2><p>通常是指声明式事务<code>@Transactional</code>的失效场景，可概括为<br><img src="/myblog/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/Spring/Spring%E4%BA%8B%E5%8A%A1%E5%A4%B1%E6%95%88%E7%9A%84%E5%9C%BA%E6%99%AF/Spring%E4%BA%8B%E5%8A%A1%E5%A4%B1%E6%95%88%E7%9A%84%E5%9C%BA%E6%99%AF.jpg"></p>
<h4 id="2-0-1-Bean未被spring管理"><a href="#2-0-1-Bean未被spring管理" class="headerlink" title="2.0.1. Bean未被spring管理"></a>2.0.1. Bean未被spring管理</h4><h4 id="2-0-2-方法的访问权限-修饰符有误"><a href="#2-0-2-方法的访问权限-修饰符有误" class="headerlink" title="2.0.2. 方法的访问权限/修饰符有误"></a>2.0.2. 方法的访问权限/修饰符有误</h4><ul>
<li><p>Java的访问权限主要有四种：private、default、protected、public，它们的权限从左到右，依次变大。如果方法的访问级别不是public,会导致事务失效</p>
</li>
<li><p>方法被final、static修饰时，会导致方法不能被spring AOP代理重写</p>
</li>
</ul>
<h4 id="2-0-3-方法属于内部调用"><a href="#2-0-3-方法属于内部调用" class="headerlink" title="2.0.3. 方法属于内部调用"></a>2.0.3. 方法属于内部调用</h4><p>如下代码中的updateModelEntity方法虽然使用了注解，但外部调用updateModleInfo方法时，再次内部调用updateModelEntity方法，该方法上的事务并不会生效。</p>
<p>（比如save方法执行失败时，removeById方法也不会回滚，这是非常严重的）</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ModelInfoServiceImpl</span> <span class="keyword">extends</span> <span class="title class_">ModelInfoService</span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    ModelOverviewService modelOverviewService;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">updateModleInfo</span><span class="params">(ModelInfoDto modelInfo)</span>&#123;</span><br><span class="line"></span><br><span class="line">        List&lt;ModelOverviewVo&gt; overviewList = modelOverviewService.selectModelOverviewByModelId(modelInfo.getModelId());</span><br><span class="line"></span><br><span class="line">        <span class="comment">//如果存在模型的概览信息,则只保留两条概览字段记录</span></span><br><span class="line">        <span class="keyword">if</span> (overviewList.size() &gt; <span class="number">2</span>) &#123;</span><br><span class="line"></span><br><span class="line">            List&lt;String&gt; overViewIds = overviewList.stream().skip(<span class="number">2</span>).map(ModelOverviewVo::getId).collect(Collectors.toList());</span><br><span class="line"></span><br><span class="line">            modelOverviewService.removeByIds(overViewIds);</span><br><span class="line">        &#125;</span><br><span class="line">     </span><br><span class="line">        <span class="comment">/*内部调用另一个事务方法*/</span></span><br><span class="line">        <span class="built_in">this</span>.updateModelEntity(modelInfo);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Transactional(rollbackFor = Exception.class)</span></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">updateModelEntity</span><span class="params">(ModelInfoDto modelInfo)</span> &#123;</span><br><span class="line"></span><br><span class="line">        <span class="type">ModelInfoEntity</span> <span class="variable">modelEntity</span> <span class="operator">=</span> <span class="built_in">this</span>.getById(modelInfo.getModelId());</span><br><span class="line"></span><br><span class="line">        <span class="comment">//设置模型的部分基础信息</span></span><br><span class="line">        modelEntity.setModelName(modelInfo.getModelName());</span><br><span class="line">        modelEntity.setModelAlias(modelInfo.getModelAlias());</span><br><span class="line">        modelEntity.setModelDesc(modelInfo.getModelDesc());</span><br><span class="line"></span><br><span class="line">        <span class="built_in">this</span>.removeById(modelEntity);</span><br><span class="line"></span><br><span class="line">        <span class="built_in">this</span>.save(modelEntity);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ModelInfoController</span>&#123;</span><br><span class="line">    </span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    ModelInfoService modelInfoService;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">updateModleInfo</span><span class="params">(<span class="meta">@RequestBody</span> ModelInfoEntity modelInfo)</span> &#123;</span><br><span class="line"></span><br><span class="line">        modelInfoService.updateModleInfo(modelInfo);</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<p><strong>原因</strong>：事务是通过Spring AOP代理来实现的，<strong>而同一个类中的方法内部调用另一个方法时，是直接调用目标方法的代码，而不是通过代理类进行调用</strong>。所以上述代码中，updateModleInfo调用updateModelEntity方法不是通过代理类进行的，因此事务不会生效。</p>
<p><strong>解决方案</strong>：</p>
<ul>
<li><p>方案1，在外部直接调用的方法上，也加上@Transactional注解。比如在updateModleInfo 方法上存在@Transactional注解时，再内部调用updateModelEntity方法(无论该方法是否使用了@Transactional)，spring会将updateModleInfo 方法整体作为一个事务，所以即使updateModelEntity方法中任何位置出错，都能够正确地回滚。</p>
  <figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="meta">@Transactional(rollbackFor = Exception.class)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">updateModleInfo</span><span class="params">(ModelInfoDto modelInfo)</span>&#123;</span><br><span class="line">    <span class="comment">//……</span></span><br><span class="line">    <span class="comment">/*内部调用另一个事务方法*/</span></span><br><span class="line">    <span class="built_in">this</span>.updateModelEntity(modelInfo);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//@Transactional 可有可无,取决于还有没有其他地方调用</span></span><br><span class="line"><span class="meta">@Transactional(rollbackFor = Exception.class)</span></span><br><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">updateModelEntity</span><span class="params">(ModelInfoDto modelInfo)</span> &#123;</span><br><span class="line">   <span class="comment">//……</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p>方案2，对于那些controller直接调用方法，不方便直接添加@Transactional的情况，可以将两个方法拆分到两个service中，让方法的调用成为service间的调用。</p>
  <figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ModelInfoServiceImpl</span> <span class="keyword">extends</span> <span class="title class_">ModelInfoService</span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    ModelOverviewService modelOverviewService;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">/*原updateModelEntity方法被抽取到ModelExecuteService中*/</span> </span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    ModelExecuteService modelExecuteService;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">updateModleInfo</span><span class="params">(ModelInfoDto modelInfo)</span>&#123;</span><br><span class="line">        <span class="comment">//……     </span></span><br><span class="line">        <span class="comment">/*使用注入的service进行调用*/</span></span><br><span class="line">        modelExecuteService.updateModelEntity(modelInfo);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ModelExecuteServiceImpl</span> <span class="keyword">extends</span> <span class="title class_">ModelExecuteService</span>&#123;</span><br><span class="line">	</span><br><span class="line">    <span class="comment">//ModelInfoServiceImpl中调用该方法时，也是使用代理模式，所以能够正确的开启事务</span></span><br><span class="line">    <span class="meta">@Transactional(rollbackFor = Exception.class)</span></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">updateModelEntity</span><span class="params">(ModelInfoDto modelInfo)</span> &#123;</span><br><span class="line">        <span class="comment">//……</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</li>
<li><p>方案3，在当前service类中注入自己，再使用service的调用</p>
  <figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ModelInfoServiceImpl</span> <span class="keyword">extends</span> <span class="title class_">ModelInfoService</span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/*将自身service注入到自己的实现类中*/</span></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    ModelInfoService modelInfoService;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">updateModleInfo</span><span class="params">(ModelInfoDto modelInfo)</span>&#123;</span><br><span class="line">		<span class="comment">//……</span></span><br><span class="line">        <span class="comment">/*内部调用另一个事务方法*/</span></span><br><span class="line">        modelInfoService.updateModelEntity(modelInfo);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Transactional(rollbackFor = Exception.class)</span></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">updateModelEntity</span><span class="params">(ModelInfoDto modelInfo)</span> &#123;</span><br><span class="line">       <span class="comment">//……</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h4 id="2-0-4-注解的传播属性设置有误"><a href="#2-0-4-注解的传播属性设置有误" class="headerlink" title="2.0.4. 注解的传播属性设置有误"></a>2.0.4. 注解的传播属性设置有误</h4><p>spring事务的传播行为包括 </p>
<ul>
<li><code>REQUIRED</code><br>  默认行为，如果当前存在事务，则加入该事务，如果当前不存在事务，则创建一个新的事务。</li>
<li><code>REQUIRES_NEW</code><br>  表示当前方法必须运行在它自己的事务中。运行到此方法时会启动一个新的事务。上层已经存在了一个事务，那么在该方法执行期间，外层的事务会被挂起。</li>
<li><code>NESTED</code><br>  表示如果当前已经存在一个事务，那么该方法将会嵌套在现有的事务中，嵌套的事务可以独立于当前事务进行单独地提交或回滚。如果当前事务不存在，那么其行为与REQUIRED一样。</li>
<li><code>MANDATORY</code><br>  如果当前存在事务，则加入该事务；如果当前不存在事务，则抛出异常。</li>
<li><code>SUPPORTS</code><br>  如果当前存在事务，则加入该事务；如果当前不存在事务，则以非事务的方式继续运行。</li>
<li><code>NOT_SUPPORTED</code><br>  以非事务的方式运行，如果当前存在事务，暂停当前的事务。</li>
<li><code>NEVER</code><br>  表示以非事务的方式运行，如果当前存在事务，则抛出异常。</li>
</ul>
<p>简单概括的话，上文中使用了事务方法，后续只有与 <code>REQUIRED</code>、<code>NESTED</code>、<code>SUPPORTS</code> 这三种传播级别的方法进行组合或嵌套时，才能使事务生效。（详细的验证过程，可以看我另一篇文章）</p>
<h4 id="2-0-5-注解的rollbackFor属性设置有误"><a href="#2-0-5-注解的rollbackFor属性设置有误" class="headerlink" title="2.0.5. 注解的rollbackFor属性设置有误"></a>2.0.5. 注解的rollbackFor属性设置有误</h4><p>例如以下代码中，如果抛出了IOException，并不是RuntimeException的子类，所以该事务将无法生效。</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="meta">@Transactional(rollbackFor = RuntimeException.class)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">updateModleInfo</span><span class="params">(ModelInfoDto modelInfo)</span> <span class="keyword">throws</span> IOException &#123;</span><br><span class="line"></span><br><span class="line">    List&lt;ModelOverviewVo&gt; overviewList = modelOverviewService.selectModelOverviewByModelId(modelInfo.getModelId());</span><br><span class="line"></span><br><span class="line">    <span class="type">String</span> <span class="variable">fileName</span> <span class="operator">=</span> modelInfo.getFileName();</span><br><span class="line"></span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        Files.newBufferedReader(Paths.get(<span class="string">&quot;./source/&quot;</span> + fileName));</span><br><span class="line">    &#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">        <span class="keyword">throw</span> e;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="built_in">this</span>.updateModelEntity(modelInfo);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<p><strong>原因</strong>：从源码可知，rollbackFor属性指定的异常必须是Throwable或者其子类。默认情况下，RuntimeException和IOException两种异常都是会自动回滚的。</p>
<p><img src="/myblog/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/Spring/Spring%E4%BA%8B%E5%8A%A1%E5%A4%B1%E6%95%88%E7%9A%84%E5%9C%BA%E6%99%AF/image-20230814164439049.png" alt="image-20230814164439049"></p>
<p>但以上的样例代码中，指定了rollbackFor = RuntimeException.class，但是抛出的异常又是IOException，二者并没有任何什么继承关系，因此事务并不会生效。</p>
<p><img src="/myblog/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/Spring/Spring%E4%BA%8B%E5%8A%A1%E5%A4%B1%E6%95%88%E7%9A%84%E5%9C%BA%E6%99%AF/image-20230814165325723.png" alt="image-20230814165325723"></p>
<h4 id="2-0-6-错误地使用了多线程"><a href="#2-0-6-错误地使用了多线程" class="headerlink" title="2.0.6. 错误地使用了多线程"></a>2.0.6. 错误地使用了多线程</h4><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="meta">@Transactional(rollbackFor = RuntimeException.class)</span></span><br><span class="line"><span class="keyword">public</span> R&lt;UserTokenInfo&gt; <span class="title function_">login</span><span class="params">(<span class="meta">@RequestBody</span> <span class="meta">@Validated</span> LoginDto loginForm, HttpServletRequest request)</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="type">String</span> <span class="variable">loginName</span> <span class="operator">=</span> loginForm.getLoginName();</span><br><span class="line"></span><br><span class="line">    <span class="type">String</span> <span class="variable">passWord</span> <span class="operator">=</span> loginForm.getPassWord();</span><br><span class="line"></span><br><span class="line">    <span class="comment">//登录获取token信息</span></span><br><span class="line">    <span class="type">UserTokenInfo</span> <span class="variable">userTokenInfo</span> <span class="operator">=</span> userService.login(loginName, passWord);</span><br><span class="line"></span><br><span class="line">    <span class="comment">//(异步)记录当前登录的日志</span></span><br><span class="line">    ThreadUtil.execAsync(() -&gt; logService.insertUserLoginLog(userTokenInfo.getUserId(), request.getRemoteHost(), request.getRequestURI()));</span><br><span class="line"></span><br><span class="line">    <span class="comment">//其他业务操作</span></span><br><span class="line">    …………</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">return</span> R.ok(userTokenInfo, userTokenInfo.getToken());</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<p>这段代码中关于日志的记录使用了异步线程去处理，如果后续其他业务操作出现了异常，只会回滚主线程内的数据信息，异步线程中处理的日志信息，则不会被回滚。</p>
<p><strong>原因</strong>：方法内部使用多线程处理DB时，每个线程都会新申请一个Connection连接并存放到自己的ThreadLocal里面，@Transactional 方法所在的主线程获取不到内部子线程的连接，所以无法回滚。 </p>
<p><em>这部分能从源码中轻松解读出来, 感兴趣的同学可以阅读下，重点是TransactionSynchronizationManager类中的方法</em></p>
<p><strong>解决方案</strong>：配合TransactionSynchronizationManager类中的bindResource方法，将多个线程使用的连接设置为同一个。并且需要确保子线程的异常能够正确地向外抛出。</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="meta">@Transactional(rollbackFor = RuntimeException.class)</span></span><br><span class="line"><span class="keyword">public</span> R&lt;UserTokenInfo&gt; <span class="title function_">login</span><span class="params">(<span class="meta">@RequestBody</span> <span class="meta">@Validated</span> LoginDto loginForm, HttpServletRequest request)</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/*1.获取主线程中的数据库连接*/</span></span><br><span class="line">    <span class="type">ConnectionHolder</span> <span class="variable">conHolder</span> <span class="operator">=</span> (ConnectionHolder) TransactionSynchronizationManager.getResource(dataSource);</span><br><span class="line"></span><br><span class="line">    <span class="type">String</span> <span class="variable">loginName</span> <span class="operator">=</span> loginForm.getLoginName();</span><br><span class="line"></span><br><span class="line">    <span class="type">String</span> <span class="variable">passWord</span> <span class="operator">=</span> loginForm.getPassWord();</span><br><span class="line"></span><br><span class="line">    <span class="comment">//登录获取token信息</span></span><br><span class="line">    <span class="type">UserTokenInfo</span> <span class="variable">userTokenInfo</span> <span class="operator">=</span> userService.login(loginName, passWord);</span><br><span class="line"></span><br><span class="line">    Future&lt;?&gt; future = ThreadUtil.execAsync(() -&gt; &#123;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/*2.在子线程操作前更换其使用的连接*/</span></span><br><span class="line">        TransactionSynchronizationManager.bindResource(dataSource, conHolder); </span><br><span class="line"></span><br><span class="line">        <span class="comment">//记录当前登录的日志</span></span><br><span class="line">        logService.insertUserLoginLog(userTokenInfo.getUserId(), request.getRemoteHost(), request.getRequestURI());</span><br><span class="line"></span><br><span class="line">        <span class="comment">//模拟出现异常</span></span><br><span class="line">        <span class="type">int</span> <span class="variable">x</span> <span class="operator">=</span> <span class="number">1</span> / <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/*3.操作完成后,移除绑定的连接*/</span></span><br><span class="line">        TransactionSynchronizationManager.unbindResource(dataSource);</span><br><span class="line">    &#125;);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        future.get();</span><br><span class="line">    &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">        logger.error(e);</span><br><span class="line">		<span class="comment">//将线程内部出现的错误向外抛出</span></span><br><span class="line">        <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">RRException</span>(<span class="string">&quot;日志记录出错&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> R.ok(userTokenInfo, userTokenInfo.getToken());</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>总结</strong>：Spring事务管理器是使用线程本地变量（ThreadLocal）来保证线程安全的，Spring事务是基于线程绑定的，<strong>每个线程都有自己的事务上下文</strong>，能够确保了事务操作的隔离性和一致性。严格来说并不是Spring使用多线程方法操作数据库会导致事务回滚失效，而是我们操作多线程时，没有去统一线程间使用的Connection对象，并且未能将子线程的异常抛出时，就会造成子线程的数据库操作无法回滚的问题。</p>
<h4 id="2-0-7-异常的处理有误"><a href="#2-0-7-异常的处理有误" class="headerlink" title="2.0.7. 异常的处理有误"></a>2.0.7. 异常的处理有误</h4><ul>
<li><p>捕获了数据库异常但是未能抛出，自己把异常吞了。</p>
  <figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="meta">@Transactional(rollbackFor = Exception.class)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">updateModleInfo</span><span class="params">(ModelInfoDto modelInfo)</span> &#123;</span><br><span class="line"></span><br><span class="line">    List&lt;ModelOverviewVo&gt; overviewList = modelOverviewService.selectModelOverviewByModelId(modelInfo.getModelId());</span><br><span class="line"></span><br><span class="line">    <span class="comment">//如果存在模型的概览信息,则只保留两条概览字段记录</span></span><br><span class="line">    <span class="keyword">if</span> (overviewList.size() &gt; <span class="number">2</span>) &#123;</span><br><span class="line"></span><br><span class="line">        List&lt;String&gt; overViewIds = overviewList.stream().skip(<span class="number">2</span>).map(ModelOverviewVo::getId).collect(Collectors.toList());</span><br><span class="line"></span><br><span class="line">        modelOverviewService.removeByIds(overViewIds);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//更新模型基本信息</span></span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.updateModelEntity(modelInfo);</span><br><span class="line">    &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">        logger.error(<span class="string">&quot;模型基本信息更新失败&#123;&#125;&quot;</span>, e);</span><br><span class="line">        <span class="comment">/*想要使整体的事务失效，必须将异常向外抛出去*/</span></span><br><span class="line">        <span class="keyword">throw</span> e;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p>抛出了不会被外层捕获的异常。也就是上面提到的rollbackFor中设定的异常与实际抛出异常，二者不存在包含关系。</p>
</li>
</ul>
<h4 id="2-0-8-欢迎补充"><a href="#2-0-8-欢迎补充" class="headerlink" title="2.0.8. 欢迎补充"></a>2.0.8. 欢迎补充</h4></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://buqiugouda.gitee.io">不求勾搭</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://buqiugouda.gitee.io/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/Spring/Spring%E4%BA%8B%E5%8A%A1%E5%A4%B1%E6%95%88%E7%9A%84%E5%9C%BA%E6%99%AF/">http://buqiugouda.gitee.io/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/Spring/Spring%E4%BA%8B%E5%8A%A1%E5%A4%B1%E6%95%88%E7%9A%84%E5%9C%BA%E6%99%AF/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://buqiugouda.gitee.io" target="_blank">buqiugouda的博客主页</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/myblog/tags/Spring/">Spring</a></div><div class="post_share"><div class="social-share" data-image="/myblog/img/covers/cover2.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/myblog/%E5%B7%A5%E4%BD%9C%E5%A4%8D%E7%9B%98/%E5%AE%A1%E6%89%B9%E6%B5%81%E5%8A%9F%E8%83%BD%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E5%B7%A5%E4%BD%9C%E5%9B%9E%E9%A1%BE/" title="审批流功能扩展开发工作回顾"><img class="cover" src="/myblog/img/covers/note.png" onerror="onerror=null;src='/myblog/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">审批流功能扩展开发工作回顾</div></div></a></div><div class="next-post pull-right"><a href="/myblog/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/Spring%20Cloud/SpringColud%E6%A0%B8%E5%BF%83%E7%BB%84%E4%BB%B6%E6%B5%85%E6%9E%90/" title="SpringColud核心组件浅析"><img class="cover" src="/myblog/img/covers/cover4.png" onerror="onerror=null;src='/myblog/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">SpringColud核心组件浅析</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://foruda.gitee.com/avatar/1676921533047997408/590832_buqiugouda_1620800091.png" onerror="this.onerror=null;this.src='/myblog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">不求勾搭</div><div class="author-info__description">路漫漫其修远兮，吾将上下而求索！</div></div><div class="card-info-data site-data is-center"><a href="/myblog/archives/"><div class="headline">文章</div><div class="length-num">11</div></a><a href="/myblog/tags/"><div class="headline">标签</div><div class="length-num">9</div></a><a href="/myblog/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/buqiugouda"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">嗨害嗨，来啦⚔️。<br>这里有我个人编写的随笔，也有收集的资料文章。<br>内容只用于个人学习、温故而知新。<br>如有侵权,可以联系我😊</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-Spring-%E4%BA%8B%E5%8A%A1%E7%9A%84%E5%AE%9E%E7%8E%B0%E6%96%B9%E5%BC%8F"><span class="toc-number">1.</span> <span class="toc-text">1. Spring 事务的实现方式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-Spring%E4%BA%8B%E5%8A%A1%E5%A4%B1%E6%95%88%E7%9A%84%E5%9C%BA%E6%99%AF"><span class="toc-number">2.</span> <span class="toc-text">2. Spring事务失效的场景</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#2-0-1-Bean%E6%9C%AA%E8%A2%ABspring%E7%AE%A1%E7%90%86"><span class="toc-number">2.0.1.</span> <span class="toc-text">2.0.1. Bean未被spring管理</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-0-2-%E6%96%B9%E6%B3%95%E7%9A%84%E8%AE%BF%E9%97%AE%E6%9D%83%E9%99%90-%E4%BF%AE%E9%A5%B0%E7%AC%A6%E6%9C%89%E8%AF%AF"><span class="toc-number">2.0.2.</span> <span class="toc-text">2.0.2. 方法的访问权限&#x2F;修饰符有误</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-0-3-%E6%96%B9%E6%B3%95%E5%B1%9E%E4%BA%8E%E5%86%85%E9%83%A8%E8%B0%83%E7%94%A8"><span class="toc-number">2.0.3.</span> <span class="toc-text">2.0.3. 方法属于内部调用</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-0-4-%E6%B3%A8%E8%A7%A3%E7%9A%84%E4%BC%A0%E6%92%AD%E5%B1%9E%E6%80%A7%E8%AE%BE%E7%BD%AE%E6%9C%89%E8%AF%AF"><span class="toc-number">2.0.4.</span> <span class="toc-text">2.0.4. 注解的传播属性设置有误</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-0-5-%E6%B3%A8%E8%A7%A3%E7%9A%84rollbackFor%E5%B1%9E%E6%80%A7%E8%AE%BE%E7%BD%AE%E6%9C%89%E8%AF%AF"><span class="toc-number">2.0.5.</span> <span class="toc-text">2.0.5. 注解的rollbackFor属性设置有误</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-0-6-%E9%94%99%E8%AF%AF%E5%9C%B0%E4%BD%BF%E7%94%A8%E4%BA%86%E5%A4%9A%E7%BA%BF%E7%A8%8B"><span class="toc-number">2.0.6.</span> <span class="toc-text">2.0.6. 错误地使用了多线程</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-0-7-%E5%BC%82%E5%B8%B8%E7%9A%84%E5%A4%84%E7%90%86%E6%9C%89%E8%AF%AF"><span class="toc-number">2.0.7.</span> <span class="toc-text">2.0.7. 异常的处理有误</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-0-8-%E6%AC%A2%E8%BF%8E%E8%A1%A5%E5%85%85"><span class="toc-number">2.0.8.</span> <span class="toc-text">2.0.8. 欢迎补充</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/%E5%B7%A5%E4%BD%9C%E5%A4%8D%E7%9B%98/Navicat%E8%83%BD%E8%BF%9E%E6%8E%A5%E6%95%B0%E6%8D%AE%E5%BA%93%E4%BD%86IDEA%E5%92%8CDbeaver%E8%BF%9E%E4%B8%8D%E4%B8%8A/" title="Navicat能连接数据库但IDEA和Dbeaver连不上">Navicat能连接数据库但IDEA和Dbeaver连不上</a><time datetime="2023-08-23T07:45:23.000Z" title="发表于 2023-08-23 15:45:23">2023-08-23</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/%E5%B7%A5%E4%BD%9C%E5%A4%8D%E7%9B%98/%E5%AE%A1%E6%89%B9%E6%B5%81%E5%8A%9F%E8%83%BD%E6%89%A9%E5%B1%95%E5%BC%80%E5%8F%91%E5%B7%A5%E4%BD%9C%E5%9B%9E%E9%A1%BE/" title="审批流功能扩展开发工作回顾">审批流功能扩展开发工作回顾</a><time datetime="2023-03-29T12:31:18.000Z" title="发表于 2023-03-29 20:31:18">2023-03-29</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/Spring/Spring%E4%BA%8B%E5%8A%A1%E5%A4%B1%E6%95%88%E7%9A%84%E5%9C%BA%E6%99%AF/" title="Spirng事务失效的场景">Spirng事务失效的场景</a><time datetime="2020-05-14T16:00:00.000Z" title="发表于 2020-05-15 00:00:00">2020-05-15</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/Spring%20Cloud/SpringColud%E6%A0%B8%E5%BF%83%E7%BB%84%E4%BB%B6%E6%B5%85%E6%9E%90/" title="SpringColud核心组件浅析">SpringColud核心组件浅析</a><time datetime="2020-01-29T16:00:00.000Z" title="发表于 2020-01-30 00:00:00">2020-01-30</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E6%80%BB%E7%BB%93/" title="设计模式总结">设计模式总结</a><time datetime="2019-11-09T16:00:00.000Z" title="发表于 2019-11-10 00:00:00">2019-11-10</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('/myblog/img/covers/cover2.png')"><div id="footer-wrap"><div class="copyright">&copy;2019 - 2023 <i id="heartbeat" class="fa fas fa-heartbeat"></i> By 不求勾搭</div></div><link rel="stylesheet" href="https://fastly.jsdelivr.net/gh/HCLonely/images@master/others/heartbeat.min.css"></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/myblog/js/utils.js"></script><script src="/myblog/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><div class="js-pjax"></div><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-fluttering-ribbon.min.js"></script></div></body></html>